/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulos.perfil.vista;

import basedatos.OperacionesBD;
import java.awt.Image;
import javax.swing.ImageIcon;
import modulos.perfil.modelo.Perfil;
import vista.ClsInicio;
import vista.frmPrincipal;
import vista.jFrmLogin;
import vista.modelo.OperacionesVarias;
import vista.modelo.PonerImagenLabel;

/**
 *
 * @author francisco
 */
public class FrmCambiarPerfil extends javax.swing.JInternalFrame {
private String nombrePerfil;
private Image imagenFondo;
private Image imagenInicio;
    /**
     * Creates new form FrmCambiarPerfil
     */
    public FrmCambiarPerfil() {
        initComponents();
        OperacionesVarias.cerrarVentanaEscape(this);
        OperacionesVarias.centrar(this);
        poneComboPerfiles();
        perfilActual(ClsInicio.perfilActual);
        
    }

    private void perfilActual(Perfil p) {
        imagenFondo = new ImageIcon(p.getImagenPantalla()).getImage();
        imagenInicio = new ImageIcon(p.getImagenInicio()).getImage();
        lblImagenFondo.setIcon(PonerImagenLabel.loadImage(imagenFondo));
        lblImagenInicio.setIcon(PonerImagenLabel.loadImage(imagenInicio));
        txtPerfil.setText(p.getNombrePerfil());
        lblMensaje.setText(p.getTextoBarra());
    }
   private void poneComboPerfiles(){       
       for(Object o:ClsInicio.perfiles){
            Perfil p=(Perfil) o;            
            cbPerfiles.addItem(p.getNombrePerfil());
       }
   }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtPerfil = new javax.swing.JTextField();
        lblImagenInicio = new javax.swing.JLabel();
        lblImagenFondo = new javax.swing.JLabel();
        cbPerfiles = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lblMensaje = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        btnAplicar = new javax.swing.JButton();

        setTitle("CAMBIAR PERFIL");
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        jLabel1.setText("Escoja Nuevo Perfil:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(20, 60, 140, 16);

        txtPerfil.setEditable(false);
        getContentPane().add(txtPerfil);
        txtPerfil.setBounds(170, 10, 330, 30);

        lblImagenInicio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblImagenInicio.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        getContentPane().add(lblImagenInicio);
        lblImagenInicio.setBounds(310, 120, 190, 170);

        lblImagenFondo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblImagenFondo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        getContentPane().add(lblImagenFondo);
        lblImagenFondo.setBounds(80, 120, 190, 170);

        cbPerfiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPerfilesActionPerformed(evt);
            }
        });
        getContentPane().add(cbPerfiles);
        cbPerfiles.setBounds(170, 50, 330, 30);

        jLabel4.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        jLabel4.setText("Imagen Inicio");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(360, 100, 100, 20);

        jLabel5.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        jLabel5.setText("Imagen Fondo");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(130, 100, 100, 20);

        jLabel6.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        jLabel6.setText(" Texto Barra Inferior:");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(10, 310, 160, 30);

        lblMensaje.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblMensaje.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        getContentPane().add(lblMensaje);
        lblMensaje.setBounds(150, 310, 350, 30);

        jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        jLabel8.setText("Perfil Actual:");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(60, 20, 120, 16);

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/agt_home.png"))); // NOI18N
        btnCancelar.setText("Cerrar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelar);
        btnCancelar.setBounds(290, 350, 100, 30);

        btnAplicar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/accept.png"))); // NOI18N
        btnAplicar.setText("Aplicar");
        btnAplicar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAplicarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAplicar);
        btnAplicar.setBounds(160, 350, 110, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-529)/2, (screenSize.height-417)/2, 529, 417);
    }// </editor-fold>//GEN-END:initComponents

    private void cbPerfilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPerfilesActionPerformed
        Perfil p=(Perfil) OperacionesBD.buscar("Perfil", "nombrePerfil", String.valueOf(cbPerfiles.getSelectedItem()));
        perfilActual(p);
        nombrePerfil=p.getNombrePerfil();
    }//GEN-LAST:event_cbPerfilesActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAplicarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAplicarActionPerformed
        ClsInicio.poneHabilitado(nombrePerfil);
        ClsInicio.ponePerfil();
        frmPrincipal.ponePerfil();
        jFrmLogin.poneImagenLogin();
    }//GEN-LAST:event_btnAplicarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAplicar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cbPerfiles;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel lblImagenFondo;
    private javax.swing.JLabel lblImagenInicio;
    private javax.swing.JLabel lblMensaje;
    private javax.swing.JTextField txtPerfil;
    // End of variables declaration//GEN-END:variables
}
